;; =============================================================================
;; unit tests for print-c


;; =============================================================================
;; helper function that compares contents to be written to certain stream
;; with the given string
(defun ut-stream-equals-string? (stream-writer match-string)
  (let ((strstream (make-string-output-stream)))
    (funcall stream-writer strstream)
    (string= (get-output-stream-string strstream) match-string)))


;; =============================================================================
;; compares member type output
(defun ut-print-complex-type-member ()
  (let ((char (make-instance 'p-type-builtin :name "char" :size 1))
	m)
    (setf m (make-instance 'p-complex-type-member :name "foo" :type char))
    (ut-stream-equals-string?
     (lambda (stream) (print-c m stream))
     (format nil "char foo;~%"))))

;; =============================================================================
;; print struct 1 test
(defun ut-print-struct-1 ()
  (let ((char (make-instance 'p-type-builtin :name "char" :size 1))
	struct-member-1
	struct)
    (setf struct-member-1 (make-instance 'p-complex-type-member
					 :name "foo"
					 :type char))
    (setf struct (make-instance 'p-type-complex
				:name "TestStruct"
				:members (list struct-member-1)))

    (print-c struct *standard-output*)
    
    (ut-stream-equals-string?
     (lambda (stream) (print-c struct stream))
     (format nil "struct TestStruct~%{~%char foo;~%};~%"))))

;; =============================================================================
;; executes unit tests
;; (ut-print-complex-type-member)
;; (ut-print-struct-1)

(defun ut-exec-with-assert ()
  (assert (ut-print-complex-type-member))
  (assert (ut-print-struct-1))
  t)

;; (ut-exec-with-assert)

